define(function (require, exports, module) {
	var $ = require('../../libs/jquery.min.js');


	var mathNum = function (min, max) {
		return Math.random() * (max - min + 1) + min
	};

    var card = function (num, isFirst, index) {
		this.num = num;
		this.index = index;
		var _num = mathNum(-10, 10);
		this.html = $('<div class="card TA" style="left : 1000px"></div>');
		if ((num != 0) && isFirst) {
			this.html.append('<img src="./img/card/bg.jpg" style="transform:rotate(' + _num + 'deg)"/>');
			this.html.append('<div class="show-num" style="transform:rotate(' + _num + 'deg)">' + num + '</div>');
		} else if (num == 0) {
			this.html.append('<img src="./img/card/bg.jpg" style="transform:rotate(' + _num + 'deg)"/>');
		} else if (num != 0 && !isFirst) {
			this.html.append('<img src="./img/card/' + num + '.jpg" style="transform:rotate(' + _num + 'deg)"/>');
		};
	};
	card.prototype.getNum = function () {
		return this.num;
	};
	card.prototype.render = function () {
		var _this = this;
		setTimeout(function () {
			_this.html.css('left', _this.index * 45);
		}, 20);
		return this.html;
	};

	var cards = function (element) {
		this.num = 0;
		this.cardArray = [];
		this.html = $('<div class="cards"></div>');
	};
	cards.prototype.setCard = function (num) {
		var _length = this.cardArray.length;
		if (_length == 0) {
			var _card = new card(num, true, _length);
			this.cardArray.push(_card);
			this.html.append(_card.render());
		} else {
			var _card = new card(num, false, _length);
			this.cardArray.push(_card);
			this.html.append(_card.render());
        };
	};
	cards.prototype.getNums = function () {
		var num = 0;
		for (let i = 0; i < this.cardArray.length; i++) {
			const element = this.cardArray[i];
			num += element.getNum();
        };
        return num;
    };
    cards.prototype.back = function () {
        var _card = this.cardArray.pop();
        _card.html.css('left', 1000);
        setTimeout(function(){
            _card.html.remove();
        },2000);
    };

	cards.prototype.render = function () {
		return this.html;
    };
    return function () {
        return new cards();
    };

});